package com.zls.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zls.pojo.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface TTaskMapper extends BaseMapper<TTask> {
    @Results(id = "ttaskMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "product_batches_id", property = "productBatchesId"),
            @Result(column = "content", property = "content"),
            @Result(column = "state", property = "state"),
            @Result(column = "img1", property = "img1"),
            @Result(column = "img2", property = "img2"),
            @Result(column = "img3", property = "img3"),
            @Result(column = "img4", property = "img4"),
            @Result(column = "producter_id", property = "producterId"),
            @Result(column = "sys_user_id", property = "sysUserId"),
            @Result(column = "farm_id", property = "farmId"),
            @Result(column = "activity_date", property = "activityDate"),
            @Result(column = "area", property = "area"),
            @Result(column = "update_time", property = "updateTime"),
            @Result(column = "desc_content", property = "descContent"),
            @Result(column = "finish_date", property = "finishDate"),
            @Result(column = "create_date", property = "createDate"),
            @Result(column = "product_batches_id", property = "productBatches", javaType = ProductBatches.class, one =
            @One(select = "com.zls.mapper.ProductBatchesMapper.selectById", fetchType = FetchType.EAGER)),
            @Result(column = "producter_id", property = "tProducter", javaType = TProducter.class, one =
            @One(select = "com.zls.mapper.TProducterMapper.selectById", fetchType = FetchType.EAGER)),
            @Result(column = "sys_user_id", property = "sysUser", javaType = SysUser.class, one =
            @One(select = "com.zls.mapper.SysUserMapper.selectById", fetchType = FetchType.EAGER)),
            @Result(column = "farm_id", property = "tFarm", javaType = TFarm.class, one =
            @One(select = "com.zls.mapper.TFarmMapper.selectById", fetchType = FetchType.EAGER)),
    })
    @Select("<script>" +
            "select * from t_task where 1=1" +
            "<if test='queryString!=null'> and content like concat( '%',#{queryString},'%') ORDER BY state " +
            "limit #{currentPage},#{pageSize}</if>" +
            "<if test='queryString==null'>ORDER BY state limit #{currentPage},#{pageSize}</if> "+
            "</script>")
    List<TTask> findPage(@Param("currentPage") Integer currentPage, @Param("pageSize") Integer pageSize, @Param("queryString") String queryString);

    //查询总记录数
    @Select("<script>" +
            "select count(*) from t_task where 1 =1" +
            "<if test='queryString!=null'> and content like concat( '%',#{queryString},'%') </if>" +
            "</script>")
    Long count(String queryString);

    @Insert("INSERT INTO t_task  (product_batches_id,sys_user_id ,content, producter_id,farm_id,area,create_date )" +
            " VALUES  (#{productBatchesId},#{sysUserId},#{content},#{producterId},#{farmId},#{area},#{createDate})")
    Integer addTTask(TTask tTask);

    @ResultMap("ttaskMap")
    @Select("select * from t_task where producter_id=#{id} and state=1 or producter_id=#{id} and state=2 ORDER BY state")
    List<TTask> selectByProId(int id);

}
